/**
 * Created by jiangxj on 2017/3/1.
 * 拆分过后项目微信相关api封装（微页面专用）
 */

(function ($) {
    var host =  window.location.host;
    var wx_server = "http://wxapi.vlearn.cn/wecastsvr";//微信服务器请求接口地址
    if(host.indexOf('.vstudy.net.cn') > 0){
        wx_server = "http://wxapi.vstudy.net.cn/wecastsvr";
    }

    function request(config) {
        $.ajax({
            url: wx_server,
            data: config['params'],
            dataType: "json",
            type: config['type'],
            cache: false,
            contentType: "application/x-www-form-urlencoded; charset=utf-8",
            success: function (data) {
                if(typeof config['callback'] !== 'undefined')
                    config['callback'](data);
            },
            error: function (data) {
                // alert('333='+JSON.stringify(data));
            }
        });
    }

    var WxApi = {
        GET: function (params, callback) {
            request({
                params:params,
                type:'GET',
                callback:callback
            });
        },
        POST: function (params, callback) {
            request({
                params:params,
                type:'POST',
                callback:callback
            });
        }
    };

    if (!window.WxApi) {
        window.WxApi = WxApi;
    }

})(jQuery);

